﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Data;
using WPFExcelReport.Controls;
using WPFExcelReport;
using System.ComponentModel;
namespace WPFExcelReport
{
    public partial class TPRMF03
    { 

        #region ==ABFBNRKRS===========
        public static readonly DependencyProperty ABFBNRKRSProperty = DependencyProperty.Register("ABFBNRKRS",
            typeof(string), typeof(TPRMF03),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnABFBNRKRSChanged));
        public string ABFBNRKRS
        {
            get
            {
                return (string)GetValue(ABFBNRKRSProperty);
            }
            set
            {
                SetValue(ABFBNRKRSProperty, value);
            }
        }
        private static void OnABFBNRKRSChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TPRMF03;
            if (src != null)
            {
                src.ABFBNRKRS = (string)e.NewValue;
            }
        }
        #endregion

        #region ==ABFBLFDNR===========
        public static readonly DependencyProperty ABFBLFDNRProperty = DependencyProperty.Register("ABFBLFDNR",
            typeof(string), typeof(TPRMF03),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnABFBLFDNRChanged));
        public string ABFBLFDNR
        {
            get
            {
                return (string)GetValue(ABFBLFDNRProperty);
            }
            set
            {
                SetValue(ABFBLFDNRProperty, value);
            }
        }
        private static void OnABFBLFDNRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TPRMF03;
            if (src != null)
            {
                src.ABFBLFDNR = (string)e.NewValue;
            }
        }
        #endregion

        #region ==ABFBPOS===========
        public static readonly DependencyProperty ABFBPOSProperty = DependencyProperty.Register("ABFBPOS",
            typeof(string), typeof(TPRMF03),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnABFBPOSChanged));
        public string ABFBPOS
        {
            get
            {
                return (string)GetValue(ABFBPOSProperty);
            }
            set
            {
                SetValue(ABFBPOSProperty, value);
            }
        }
        private static void OnABFBPOSChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TPRMF03;
            if (src != null)
            {
                src.ABFBPOS = (string)e.NewValue;
            }
        }
        #endregion 

        public TPRMF03()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VICC_MKRF(); 
            DataContext = MV;
            InitializeComponent();

        }
       
 
        private void btnSClear_Click(object sender, RoutedEventArgs e)
        {
            //cvSMKRF.CustomFilter = null;
        }

        private void btnSFilter_Click(object sender, RoutedEventArgs e)
        {
            if (txtDate.Text.ToString().Trim() == "")
            {
                MessageBox.Show("请输入截止日期!");
                return;
            }
            string filter = "MKFPLDATV<=" + txtDate.Text.ToString() + "";
            //cvMKRF.CustomFilter = filter;
            DataRow[] rows =MV.SetData.Tables["ICC_MKRF"].Select(filter);
            if (rows.Length > 0)
            {
                DataTable tb = rows.CopyToDataTable();
                MergeData(tb.DataSet, false, true);
            }
        }
        public override void QueryCommand(object sender, RoutedEventArgs e)
        {
            dwData = TBMain.NewRow();
            dwData["ABFMANDANT"] = app.Mandant;
            dwData["ABFKSTKRS"] = KSTKRS;
            dwData["ABFKST"] = KST;
            dwData["ABFAGANG"] = AGANG;
            SResult =TMV.QTMKRF03(dwData);
            MergeData(SResult, false); 
            base.QueryCommand(sender, e);
        }

        private void btnPrint_Click(object sender, EventArgs e)
        { 
            DataSet Set = new DataSet();
            Set.Merge(MV.SetProd);
            cDR.PRINT(Set); 
        } 
    }
}